package com.ldzy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ldzy.dao.RoomMapper;
import com.ldzy.pojo.Room;
import com.ldzy.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;
    @Override
    public Page<Room> selectNewRooms(Integer pageNum, Integer pageSize, Room room) {
        PageHelper.startPage(pageNum,pageSize);//设置分页插件的参数
        Page<Room> rooms=roomMapper.selectNewRooms(room);//启动dao的分页查询对数据执行查询
        return rooms;
    }

    @Override
    public Room findById(int id) {
        Room room=roomMapper.findById(id);
        return room;
    }

    @Override
    public int edit(Room room) {
       return roomMapper.edit(room);
    }

    @Override
    public Page<Room> selectBorrowedRooms(Integer pageNum, Integer pageSize, Room room) {
        PageHelper.startPage(pageNum,pageSize);//设置分页插件的参数
        Page<Room> rooms=roomMapper.selectBorrowedRooms(room);//启动dao的分页查询对数据执行查询
        return rooms;
    }

    @Override
    public Room returnRoom(int id) {
        Room room=this.findById(id);
        room.setStatus("0");
        room.setAge("");
        room.setTenement("");
        roomMapper.edit(room);
        return room;
    }


}
